home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software of the Month Club 1996 June
/
Software of the Month Club 1996 June.iso
/
mac
/
ISO9660
/
DOS
/
DTP
/
AURORA
/
EXAMPLE.AML
< prev
next >
Wrap
Text File
|
1995-02-24
|
20KB
|
692 lines
// ───────────────────────────────────────────────────────────────────
// The Aurora Editor v2.0
// Copyright 1993-1995 nuText Systems. All Rights Reserved Worldwide.
//
// AML examples and code fragments
// ───────────────────────────────────────────────────────────────────
// Example 1 --------------------------------------------------
// mark the entire file
// (assigned to <f12> key - place in the "edit" object)
key <f12>
markline 1 (getlines)
end
// Example 2 --------------------------------------------------
// Demonstrates block marking without having the cursor resize the mark
// (for compatability with the old 'DrawMark' config setting in v1.2)
key <alt l>
markline
stopmark // stopmark closes the mark
key <alt a>
markchar
stopmark
key <alt b>
markcolumn
stopmark
// Example 3 --------------------------------------------------
// block copy without moving the mark (provided for compatibility
// with the old 'MoveMark' config setting in v1.2)
// block copy
key <alt c>
undobegin // group together as one undoable operation
curr_mark = getmarkuse // get the default markid
copymark curr_mark 'T' // create temp copy of original mark
usemark 'T' // use the temp mark
copyblock2 // copy marked text (moves the mark also)
destroymark // destroy the temp mark
usemark curr_mark // switch back to the original mark
undoend
end
// Example 4 --------------------------------------------------
// Automark example - creates a temporary paragraph mark if
// no mark exists (provided for compatibility with the old
// AutoMark configuration setting in v1.2)
// begin automark
function begauto
if not mark? then // if no mark exists...
set _am ON // set a flag
markpara // mark the current paragraph
end
end
// end automark
function endauto
if _am then // if flag was set..
set _am OFF // unset flag
destroymark // destroy the temporary mark
end
end
// usage example (indent a block)
key <shift f8>
begauto
shiftblock 1
endauto
end
// Example 5 --------------------------------------------------
// define <home> and <end> key behaviour to match the the old
// RepEnd config setting in v1.2 (provided for compatibility
// with v1.2)
// <home> key
key <home>
if getcol == 1 then // at col 1?
up // then move up 1 line
else
col 1 // otherwise move to column 1
end
end
// <end> key
key <end>
end_of_line = getlinelen + 1 // get column after end-of-line
if getcol == end_of_line then // are we there already?
down // move down 1 line
col getlinelen + 1 // move to end-of-line on new line
else
col end_of_line // move to end-of-line
end
end
// Example 6 --------------------------------------------------
// Find the last string with wrap around (provided for compatibility
// with the old 'SearchWrap' config setting in v1.2)
function findlastw
var search_str
var options
// get last find string
history_str = gethiststr "_find"
// do the search. If not found...
if not search2 history_str '' TRUE then
// wrap to top or bottom
if (splitstr '' history_str ref search_str ref options ) >= 2 and
(pos 'r' options) then
row (getlines)
col getlinelen + 1
else
gotopos 1 1
end
// do the search again
search2 history_str
end
end
// usage example
key <ctrl l> findlastw
// Example 7 --------------------------------------------------
// Change the left and right cursor keys to wrap to the previous or
// next line
// cursorleft with wrap
key <left>
if getcol == 1 then // wrap if at column 1
if up then // ..and not at first line
col getlinelen + 1
end
else
left
end
end
// cursorright with wrap
key <right>
if getcol > getlinelen then // wrap if at end-of-line
if down then // ..and not at last line
col 1
end
else
right
end
end
// Example 8 --------------------------------------------------
// change the <del> key to delete a block if marked,
// otherwise delete a character
key <del>
if mark? then
deleteblock // delete block if it exists,
else
delchar2 // otherwise delete a character
end
end
// Example 9 --------------------------------------------------
// find the word at the cursor
// (assigned to <ctrl f11>)
key <ctrl f11>
wordstr = getword // get word using the default charset
if wordstr then
search2 wordstr // find the word
else
say "no word at the cursor" 'b'
end
end
// Example 10 -------------------------------------------------
// insert a ruler line above the current line
// (assigned to <alt k> key)
key <alt k>
insabove "····+····1····+····2····+····3····+····4····+····5····+····6····+····7····+····8"
end
// Example 11 -------------------------------------------------
// emulate the QEdit 'GetPrev' <ctrl -> command: copies characters
// from the line above the current line (assigned to <alt 4> key)
key <alt 4>
if getrow > 1 then // if after first line...
writetext (getchar (getcol) getrow - 1) // get char and write it
end
end
// Example 12 -------------------------------------------------
// Emulation of Brief-style <home> and <end> keys. These keys should
// be placed in the 'edit' object:
// brief <home> key emulation (br)
key <home>
col 1 // goto column 1
smark // cua marking
keycode = getkey // get next key
if keycode == <home> then // <home> pressed 2nd time?
row (getviewtop) // goto to page top
smark // cua marking
keycode = getkey // get next key
if keycode == <home> then // <home> pressed 3rd time?
row 1 // goto to top of file
smark // cua marking
else
queuekey keycode // execute key normally
end
else
queuekey keycode // execute key normally
end
end
// brief <end> key emulation (br)
key <end>
col getlinelen + 1 // goto end-of-line
smark // cua marking
keycode = getkey // get next key
if keycode == <end> then // <end> pressed 2nd time?
row (getviewbot) // goto to page bottom
smark // cua marking
keycode = getkey // get next key
if keycode == <end> then // <end> pressed 3rd time?
row (getlines) // goto to bottom of file
smark // cua marking
else
queuekey keycode // execute key normally
end
else
queuekey keycode // execute key normally
end
end
// Example 13 -------------------------------------------------
// shows how to 'double-up' key usage for some keys by testing
// for the <shift> key
key <alt k>
if shiftkey? then // <alt shift k>
.
.
else // <alt k>
.
.
end
end
// Example 14 -------------------------------------------------
// prompts the user for the name of a program and passes the word
// at the cursor to it as the first parameter
key <shift f12>
parm = getword _CSetB // get word using charset CSetB
if parm then
program = ask "Program to execute" // prompt user for program
if program then // program entered?
run program + ' ' + parm "ck" // concatenate program with word
end // and execute it
else
say "no word at the cursor" 'b' // no word found at the cursor
end
end
// Example 15 -------------------------------------------------
// strip leading or trailing spaces from a string
// return string 'charstring' without leading spaces
function stripl (charstring)
return charstring [posnot ' ' charstring : 0]
end
// return string 'charstring' without trailing spaces
function stript (charstring)
return charstring [1 : posnot ' ' charstring 'r']
end
// Example 16 -------------------------------------------------
// attach "properties" to a string value in the current object
// (demonstrates the use of setx, lookup, unsetx)
// set a property
function setprop (string prop value)
setx string + '-' + prop value
end
// get a property
function getprop (string prop)
lookup string + '-' + prop
end
// delete a property
function delprop (string prop)
unsetx string + '-' + prop
end
// Example 17 -------------------------------------------------
// modify the save-as prompt to change the file name
// (replace function "asksaveas" in EXT.AML)
function asksaveas (options)
file = ask "Save " + (getname (getbufname)) + " as" "_load"
if file then
file = qualify file (getbufname)
addhistory "_load" file
save file options // save file with name "file"
setname file // name current file "file"
end
end
// Example 18 -------------------------------------------------
// Compute the factorial of a number (illustrates AML recursion)
function fact (x)
if? x <= 1 1 x * (fact x - 1)
end
// display the factorial of 6
say (fact 6)
// Example 19 -------------------------------------------------
// generate a random number between a and b
// (demonstrates the use of the rand function)
function random (a b)
a + (rand mod b - a + 1)
end
// display random number between 500 and 3000
say (random 500 3000)
// Example 20 -------------------------------------------------
// asynchronous beep
// (set a timer to stop the beep - demonstrates the use of timers)
function beep2 (freq duration)
if not arg then
// stop the beep
beep
else
// beep indefinitely
beep freq
// call this function again after 'duration' milliseconds
settimer "beep" duration '' "beep2"
end
end
// Example 21 -------------------------------------------------
// Check newly open files for tab chars. Expand tabs if found.
// (Place this section of aml code at the end of the 'onopen'
// function in the 'edit' object in EXT.AML - The 'onopen' function
// is called after a file is loaded and before it is displayed)
if not getbinarylen then // only for non-binary files
markline 1 20 // create a mark (first 20 lines)
if find (char 9) "bgn*" then // search for tab char in the mark
markline 1 (getlines) // extend the mark to end-of-file
tabblock _TabWidth // expand tabs using TabWidth
bufferflag '-m' // turn off buffer-modified flag
end
destroymark // destroy the temporary mark
end
// Example 22 -------------------------------------------------
// toggle the case of the character at the cursor
// (assigned to <alt k>)
key <alt k>
ovltext (flipcase (getchar)) // toggle the character
right // move right one column
end
// Example 23 -------------------------------------------------
// transpose the characters at the cursor
// (assigned to <alt k>)
// method 1: using a marked block
key <alt k>
undobegin // beginning of an undoable group
usemark 'T' // use temporary mark 'T'
markchar // create a character mark
stopmark // stop the cursor from extending the mark
right 2 // move right two columns
moveblock // move the marked character
destroymark // destroy the mark
usemark // switch back to mark '*'
undoend // end of an undoable group
end
// method 2: using a string
key <alt k>
twochars = gettext (getcol) 2
ovltext (if? twochars [2] twochars [2] ' ') + twochars [1]
right
end
// Example 24 -------------------------------------------------
// macro code fragment to synchronously dispatch all the events
// currently in the event queue
endprocess // queue an internal 'queue quit' event
process // process all events and return
// Example 25 -------------------------------------------------
// macro code fragment to display a timed message box
// set a timer (t1) to simulate the <esc> key one second from now
settimer "t1" 1000 '' <esc>
// display a short-style message box
shortbox "timed message"
// Example 26 -------------------------------------------------
// modify the prompt history menu to automatically enter selected
// strings into the prompt
// replace the <pgup> and <pgdn> keys in the 'prompt' object
// in KBD.AML
key <pgup>
if askhistory then
queue <enter>
end
end
key <pgdn> call <pgup>
// ..also modify the <lbutton> function in the 'prompt' object
// in MOUSE.AML to handle mouse clicks on the prompt retrieve tab
// left button down
function <lbutton>
.
.
case getregion
// modify this 'when' clause
when 14
if askhistory then
queue <enter>
end
.
.
// Example 27 -------------------------------------------------
// The following is an example of an external macro which can
// be run from the command line (without actually starting the
// editor). This macro replaces all occurrences of a search
// string in a file:
if loadbuf (arg 2) then // load a file
replace (arg 3) (arg 4) (arg 5) + 'a' // replace all string(s)
savebuf (arg 2) // save the file
end
// assuming this macro was compiled to 'replace.x', the following
// command will run the macro from the DOS command line:
C>a -xreplace.x "myfile.txt" "apples" "oranges" 'i'
// replaces all occurrences of 'apples' with 'oranges',
// in 'myfile.txt', ignoring case
// Example 28 -------------------------------------------------
// The following example shows how to locate a file in a path
// defined by a DOS environment string:
file = locatefile "program.exe" (getenv 'PATH')
// 'PATH' must be in caps
msgbox "Filename is: " + file
// filename is fully qualified
// Example 29 -------------------------------------------------
// To change the file manager to recognize unshifted characters as
// command codes (like Aurora v1.2), modify the <char> key
// definition in the fmgr object in KBD.AML:
key <char> (c)
.
.
// <shift-character> commands
elseif not shiftkey? then // add 'not' to this line
.
.
// (note that this will also change each file manager search
// 'hotkey' to <shift-hotkey>)
// Example 30 -------------------------------------------------
// The following macro code shows how to put a simple real-time clock on
// the edit window title bar:
object edit
.
// called every second
function onesec
settitle getbufname + ' ' + gettime
end
.
.
end
// called when the editor is started
function onentry
.
// set a timer to call 'onesec' every second
setrepeat 'sec' 1000 '' "onesec"
.
.
end
// Example 31 -------------------------------------------------
// The following macro code shows how set an alarm to go off every
// hour on the hour in edit windows and file manager windows
object edit_fmgr
.
// called on the hour (Big Ben clock chime)
function onhour
beep 330 600
beep 262 600
beep 294 600
beep 196 1200
beep 196 600
beep 294 600
beep 330 600
beep 262 1200
end
.
.
end
// called when the editor is started
function onentry
.
// set an alarm timer to call 'onhour' every hour on the hour
setalarm 'hr'
-1 // any year
-1 // any month
-1 // any day
-1 // any weekday
-1 // any hour
0 // only at zero minutes past the hour
0 // only at zero seconds past zero minutes
'' // dispatch in the current event object
'onhour' // execute the function 'onhour'
.
.
end
// Example 32 -------------------------------------------------
// The following macro code shows how to create a persistent
// real-time clock window which is updated every second:
// create a new clock object descended from the 'win' object,
// so it can inherit the mouse handling and other capabilities
// of 'desktop' windows (like edit and file manager windows)
object clock (win)
// called every second to update the date and time
function tick
gotowindow "clock"
writestr getdate + ' ' + gettime (color brightred on black) 4 2
gotowindow
end
// destroy the timer if the clock window is closed
key <esc>
destroytimer "clk"
pass
end
function "≡"
call <esc>
end
// provide keyboard support for switching windows
key <ctrl a>
nextwindow
end
// (be sure to change the object if unrelated code follows)
.
.
object edit
// create the clock window and start the clock (this could actually
// be placed in any convenient object or function, or it could
// be an external macro)
key <alt k>
createwindow 'clock'
// route window events to the clock object above
setwinobj "clock"
setframe ">b"
setwinctrl '≡'
setcolor border_color color white on gray
setcolor text_color color black on gray
settitle "Clock" 'c'
setborder "i1"
setshadow 2 1
// center the window
width = (sizeof getdate + gettime) + 9
height = 4
ox = (getvidcols - width) / 2
oy = (getvidrows - height) / 2
sizewindow ox oy ox + width oy + height "ad"
// simulate the first tick
sendobject "clock" "tick"
// start the clock timer
setrepeat 'clk' 1000 'clock' "tick"
end